package com.sc.smartcommunity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.smartcommunity.domain.Access;
import com.sc.smartcommunity.domain.Activity;
import com.sc.smartcommunity.domain.OwnerComplaint;
import com.sc.smartcommunity.service.AccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/access")
public class AccessController {
    @Autowired
    private AccessService accessService;

    @PostMapping("/submit")
    public String addAccess(@RequestBody Access access) {
        boolean result = accessService.saveAccess(access);
        if (result) {
            return "成功";
        } else {
            return "失败";
        }
    }
    @GetMapping("/page")
    public Map<String, Object> getActivities(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String title) {


        IPage<Access> accessIPage = accessService.getAccessRecordsByPage(pageNum, pageSize);
        Map<String, Object> result = new HashMap<>();
        result.put("total", accessIPage.getTotal());
        result.put("list", accessIPage.getRecords());
        result.put("pages", accessIPage.getPages());
        return result;
    }

}
